﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SoftHotel.Models;
using System.Globalization;

namespace SoftHotel.Controllers
{
    public class DetalleReservaEvController : Controller
    {
        //
        DetalleReservaEvDAO detResDAO = new DetalleReservaEvDAO();
        DetalleReservaEvDAO detResDAO1 = new DetalleReservaEvDAO();
        DetalleReservaEv ruta = new DetalleReservaEv();

        // GET: /DetalleReservaEv/

        public ActionResult Index(Int32 idReserva)
        {
            List<DetalleReservaEv> detReservaEvs = new List<DetalleReservaEv>();
            detReservaEvs = detResDAO.ejecutar_query(idReserva);
            return View(detReservaEvs);
        }

        //
        // GET: /DetalleReservaEv/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /DetalleReservaEv/Create

        public ActionResult Create(Int32 idReserva)
        {
            DetalleReservaEv detalle = new DetalleReservaEv();
            detalle.idReserva = idReserva;
            
            return View(detalle);
        }

        //
        // POST: /DetalleReservaEv/Create

        [HttpPost]
        public ActionResult Create(DetalleReservaEv detalle)
        {
            //try
            //{
                // TODO: Add insert logic here
            if (detResDAO.buscar_coincidencia(detalle)) {
                return View("Conflicto",detalle);
            }
            else
            {
                detResDAO.add_detalle(detalle);

                return RedirectToAction("Details", "ReservaEv", detalle);
            }
            //}
            //catch
            //{
            //    return View();
            //}C:\Documents and Settings\Administrador.WINDOWS-C5AFEEA\Escritorio\SoftHotel\SoftHotel\Views\DetalleReservaEv\Edit.cshtml
        }
        
        //
        // GET: /DetalleReservaEv/Edit/5
 
        public ActionResult Edit(Int32 id)
        {
            DetalleReservaEv detalle = new DetalleReservaEv();
            detalle= detResDAO.consultar_detalle(id);
            
            
            return View(detalle);
        }

        //
        // POST: /DetalleReservaEv/Edit/5

        [HttpPost]
        public ActionResult Edit(Int32 id, DetalleReservaEv detalle)
        {
            if (detResDAO.buscar_coincidencia(detalle))
            {
                return View("Conflicto", detalle);
            }
            else
            {
                // TODO: Add update logic here
                detResDAO.editar_detalle(id, detalle);

                return RedirectToAction("Details", "ReservaEv", detalle);
            }
        }

        //
        // GET: /DetalleReservaEv/Delete/5
 
        public ActionResult Delete(int id)
        {
            DetalleReservaEv detalle = new DetalleReservaEv();
            detalle = detResDAO.consultar_detalle(id);
            ruta.idReserva = detalle.idReserva;
            return View(detalle);
        }

        //
        // POST: /DetalleReservaEv/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, DetalleReservaEv detalle)
        {
            try
            {
                // TODO: Add delete logic here
                detResDAO.eliminar_detalle(id, detalle);
                return RedirectToAction("Details", "ReservaEv", detalle);
            }
            catch
            {
                return View();
            }
        }
    }
}
